package com.test.daily.leetcode.y2022.m06.day0624.home.v02;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Tom on 2022/6/24
 */
public class Solution {
    public static class TreeNode{
        public int value;
        public TreeNode left;
        public TreeNode right;
        public TreeNode(int value){
            this.value = value;
        }
    }
    public static List<Integer> maxValueList(TreeNode root){
        if(root == null){
            return new ArrayList<Integer>();
        }
        List<Integer> res = new ArrayList<>();
        dfs(root, 0, res);
        return res;
    }
    public static void dfs(TreeNode root, int height, List<Integer> res){
        if(height == res.size()){
            res.add(root.value);
        } else {
            res.set(height, Math.max(res.get(height), root.value));
        }
        if(root.left != null){
            dfs(root.left, height +1, res);
        }
        if(root.right != null){
            dfs(root.right, height+1, res);
        }
    }
}
